<?php
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
//$_SESSION['searchload'] = $_REQUEST['employeename'];
//$_SESSION['loadCheckTimes'] = $objects;
if (isset($_SESSION['loadCheckTimes'])) {
	include 'CheckTime.php';
	include '../Classes/PHPExcel.php';

	$result = mysql_query($query);
	$filename = $_SESSION['searchload'][3].".xlsx";
	if ($_SESSION['searchload'][3]=="") {
		$filename = "export.xlsx";
	}
	
	$contents = "Name \t ID \t Date \t In \t Out \t Late \t Early \t Off half day \t Off a day \t Overtime \t Note \t \n";
	$objPHPExcel = new PHPExcel();

	$objPHPExcel->getProperties()->setCreator('Matthew Casperson')
	->setLastModifiedBy('Matthew Casperson')
	->setTitle('Office 2007 XLSX Test Document')
	->setSubject('Office 2007 XLSX Test Document')
	->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.');
	$objPHPExcel->setActiveSheetIndex(0)
	->setCellValue('A1', 'Name')
	->setCellValue('B1', 'ID')
	->setCellValue('C1', 'Date')
	->setCellValue('D1', 'In')
	->setCellValue('E1', 'Out')
	->setCellValue('F1', 'Late')
	->setCellValue('G1', 'Early')
	->setCellValue('H1', 'Off half day')
	->setCellValue('I1', 'Off a day')
	->setCellValue('J1', 'Overtime')
	->setCellValue('K1', 'Note');

	foreach ($_SESSION['loadCheckTimes'] as $key =>  $object){
		$CT = unserialize (serialize ($object));
		
		$key = $key+2;
		$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('A'.$key, $CT->employeeName)
		->setCellValue('B'.$key, $CT->employeeID)
		->setCellValue('C'.$key, $CT->date)
		->setCellValue('D'.$key, $CT->inTime)
		->setCellValue('E'.$key, $CT->outTime)
		->setCellValue('F'.$key, $CT->late)
		->setCellValue('G'.$key, $CT->early)
		->setCellValue('H'.$key, $CT->halfDayOff)
		->setCellValue('I'.$key, $CT->aDayOff)
		->setCellValue('J'.$key, $CT->overtime)
		->setCellValue('K'.$key, $CT->note);
		/*$contents.= $CT->employeeName. " \t";
		 $contents.= $CT->employeeID. " \t";
		 $contents.= $CT->date. " \t";
		 $contents.= $CT->inTime. " \t";
		 $contents.= $CT->outTime. " \t";
		 $contents.= $CT->late. " \t";
		 $contents.= $CT->early. " \t";
		 $contents.= $CT->halfDayOff. " \t";
		 $contents.= $CT->aDayOff. " \t";
		 $contents.= $CT->overtime. " \t";
		 $contents.= $CT->note. " \n";*/
	}
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");
	header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
	header('Content-Disposition: attachment;filename="' . $filename);
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
	$objWriter->save('php://output');
}
exit;

?>

